Fixed issue with the solution not working if the topmost webpart in the page was not a list view webpart.